import pandas as pd

# df
data = {
    'A': [1, 2, 3],
    'B': ['x', 'y', 'z'],
    'C': ['p', 'q', 'r'],
    'D': ['m', 'n', 'o'],
    'E': [True, False, True]
}

df = pd.DataFrame(data)
print(df)

# vocab
vocab = {}
for index, row in df.iterrows():
    for column_name, value in row.iteritems():
        print(column_name + "_" + str(value))
        vocab.setdefault(column_name + "_" + str(value), len(vocab))

print(vocab)

new_df = pd.DataFrame(columns=range(len(vocab)))
print(new_df)
print(df.shape)
for index, row in df.iterrows():
    new_df.loc[index] = 0.0
    for column_name, value in row.iteritems():
        print(column_name + "_" + str(value))
        index_in_vocab = vocab[column_name + "_" + str(value)]
        # new_df[index][index_in_vocab] = 1.0  # fixme 我是傻逼, df[]是取列
        new_df.loc[index, index_in_vocab] = 1.0
        print(f"set {index}, {index_in_vocab} = 1")
        # print(new_df)

print(new_df)
print(df)
